package com.oristand.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oristand.mapper.ManufacturerMapper;
import com.oristand.pojo.Manufacturer;
import com.oristand.service.ManufacturerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 厂商接口的实现类，用来实现了service层的逻辑
 * 使用了一个mapper层的接口
 * @author dingweien
 * @version 1.0
 * @Date 2021/11/29 15:39
 */
@Service
public class ManufacturerServiceImpl implements ManufacturerService {

    private ManufacturerMapper manufacturerMapper;

    @Autowired
    public void setManufacturerMapper(ManufacturerMapper manufacturerMapper) {
        this.manufacturerMapper = manufacturerMapper;
    }

    /**
     * 查找全部厂商对象
     * @return
     */
    @Override
    public List<Manufacturer> findManufacturerList() {
        QueryWrapper<Manufacturer> manufacturerQueryWrapper = new QueryWrapper<>();
        //必须实施status为1的厂商对象，表示该厂商正在运作
        manufacturerQueryWrapper.eq("status",1);
        return manufacturerMapper.selectList(manufacturerQueryWrapper);
    }

    /**
     * 根据厂商对应的ID来查找厂家
     * @param manufacturerId 厂商
     * @return 返回厂商编号
     */
    @Override
    public Manufacturer findByManufacturerId(int manufacturerId) {
        return manufacturerMapper.selectById(manufacturerId);
    }

    /**
     * 根据厂商的Id来更新厂家的详细信息
     * @param manufacturer 厂商
     * @return 返回更新后受影响的行数，返回值为1或0
     */
    @Override
    public int updateManufacturerById(Manufacturer manufacturer) {
        return manufacturerMapper.updateById(manufacturer);
    }

    /**
     * 根据厂商的Id来删除厂商信息
     * @param manufacturerId 厂商ID
     * @return 返回删除后受影响的行数，返回值为1或0
     */
    @Override
    public int deleteManufacturerById(Integer manufacturerId) {
        return manufacturerMapper.deleteById(manufacturerId);
    }

    /**
     * 插入新的厂商信息
     * @param manufacturer 厂商
     * @return 返回插入后受影响的行数，为1或0
     */
    @Override
    public int insertManufacturer(Manufacturer manufacturer) {
        return manufacturerMapper.insert(manufacturer);
    }
}